#!/usr/bin/env/python3
# -*- coding: utf-8 -*-

"""
@Time    : 2020/3/4 10:56
@Author  : Chen Liu
@FileName: di_gui.py
@Software: PyCharm
"""

# 递归题目集合


# 1.反转字符串,直接打印出反转后的结果
def reverse_str(s, index):
    if not s or index >= len(s):
        return
    reverse_str(s, index + 1)
    print(s[index])


# 2.原地反转字符串--在原来的字符串上进行反转,双指针法
def reverse_s(s):
    start = 0
    end = len(s)

    print("s: ", s)

    while start < end:
        s[start], s[end-1] = s[end-1], s[start]
        start += 1
        end -= 1


# 3.利用递归反转字符串，添加函数，在内部函数内递归
def reverse(s):
    def helper(left, right):
        if left < right:
            s[right], s[left] = s[left], s[right]
            helper(left+1, right-1)

        helper(0, len(s)-1)


if __name__ == "__main__":
    # s = "今天天气真好"
    # reverse_str(s, 0)
    s = ['h', 'e', 'l', 'l', 'o']
    reverse_s(s)
    print(s)
